package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.github.pagehelper.PageInfo;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class CreditShop {
    //服装
    public static final int TYPE_CLOTH = 0;
    //食物
    public static final int TYPE_FOOD = 1;
    //过夜
    public static final int TYPE_STAY = 2;
    //交通方式
    public static final int TYPE_TRANSPORTION = 3;
    //工具
    public static final int TYPE_TOOL = 4;
    //门票
    public static final int TYPE_TICKET = 5;
    //书
    public static final int TYPE_BOOK = 6;

    //已上架
    public static final int STATE_PUTAWAY = 1;
    //已下架
    public static final int STATE_SOLDOUT = 2;
    //待上架
    public static final int STATE_WAIT = 0;

    private Long id;
    //名称
    private String name;
    //封面
    private String coverUrl;
    //价格
    private BigDecimal price;
    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd ",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;
    //上架时间
    @JsonFormat(pattern = "yyyy-MM-dd ",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date putawayTime;
    //下架时间
    @JsonFormat(pattern = "yyyy-MM-dd ",timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date soldoutTime;
    //类型
    private Integer type;
    //状态
    private Integer state;
    //内容详情
    private ProductContent content;
    //销量，关注度，库存
    private ProductPlus productPlus;
    //是否推荐
    private Integer isRecommend = 0;
    private PageInfo sub;

    public String getIsRecommendDisplay() {
        if (isRecommend == 0)
            return "否";
        else if (isRecommend == 1)
            return "是";
        else
            return "";
    }

    public String getTypeDisPlay() {
        if (type == null)
            return "";
        if (type == TYPE_CLOTH)
            return "服装";
        if (type == TYPE_FOOD)
            return "食物";
        if (type == TYPE_STAY)
            return "住宿";
        if (type == TYPE_TRANSPORTION)
            return "交通方式";
        if (type == TYPE_TOOL)
            return "工具";
        if (type == TYPE_TOOL)
            return "门票";
        if (type == TYPE_BOOK)
            return "书籍";
        else
            return "";
    }

    public String getJsonString(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("name",name);
        map.put("coverUrl",coverUrl);
        map.put("price",price);
        map.put("type",type);
        if (productPlus != null)
            map.put("count", productPlus.getCount());
        return JSONUtils.toJSONString(map);
    }
}